using Godot;
using System;

public partial class player : CharacterBody2D
{
	public const float Speed = 800.0f;

	public PlayerEnum playerEnum;

	private AnimatedSprite2D animatedSprite2D;
	public override void _Ready()
	{
		playerEnum = PlayerEnum.P1;
		animatedSprite2D = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
		SetAnimatedSprite2D("up");
	}

	public override void _PhysicsProcess(double delta)
	{
		Vector2 direction = Input.GetVector("left", "right", "up", "down");
		// GD.Print(Name, "", direction);
		this.Velocity = direction * Speed;
		if (direction.X > 0)
		{
			SetAnimatedSprite2D("right");
		}
		else if (direction.X < 0)
		{
			SetAnimatedSprite2D("left");
		}
		else if (direction.Y > 0)
		{
			SetAnimatedSprite2D("down");
		}
		else if (direction.Y < 0)
		{
			SetAnimatedSprite2D("up");
		}

		base.MoveAndSlide();
	}

	public void SetAnimatedSprite2D(string animatedSprite2DName)
	{
		string p = "p1";
		switch (playerEnum)
		{
			case PlayerEnum.P1:
				p = "p1";
				break;
			case PlayerEnum.P2:
				p = "p2";
				break;
		}
		animatedSprite2D.Play($"{p}_{animatedSprite2DName}");
	}
}
